package gk.example.fragment;

import gk.example.App;
import gk.example.BaseActivity;
import gk.example.activity.PersonalInfoActivity;
import gk.example.util.T;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.example.gkdate.R;

public class PersonalInfoChangeActivity extends BaseActivity implements
		OnClickListener {
	private EditText mEtInfoChange;
	private TextView mTvTitle;
	private Button mBtnInfoChange;
	private ImageButton mBtnBack;
	private int mPosition;
	private String mInfo;

	@Override
	protected void initView() {
		setContentView(R.layout.activity_personal_info_change);
		mEtInfoChange = (EditText) findViewById(R.id.et_info_change);
		mBtnInfoChange = (Button) findViewById(R.id.btn_info_change);
		mBtnBack = (ImageButton) findViewById(R.id.btn_back);
		mTvTitle = (TextView) findViewById(R.id.tv_top_title);
	}

	@Override
	protected void initEvent() {
		mTvTitle.setText(getResources().getString(R.string.change));
		mBtnBack.setOnClickListener(this);
		mBtnInfoChange.setOnClickListener(this);
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		mPosition = bundle.getInt("position");
	}

	private void getInfoText() {
		mInfo = mEtInfoChange.getText().toString();
		if (TextUtils.isEmpty(mInfo)) {
			T.show(this, "内容为空,请输入", Toast.LENGTH_SHORT);
			return;
		}
		switch (mPosition) {
		case 1:
			if (mInfo.length() > 8) {
				T.show(this, "昵称过长,请修改", Toast.LENGTH_SHORT);
				mInfo = "";
				return;
			}
			break;
		default:
			break;
		}
		App.BmobUser.setNickName(mInfo);
		startActivity(new Intent(PersonalInfoChangeActivity.this,
				PersonalInfoActivity.class));
		finish();

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_info_change:
			getInfoText();

			break;
		case R.id.btn_back:
			finish();
			break;
		default:
			break;
		}
	}

}
